<?php
    include APPLICATION_PATH . '/application/views/head.phtml';
    include APPLICATION_PATH . '/application/views/top.phtml';
    include APPLICATION_PATH . '/application/views/left.phtml';
?>
 <script >
$(document).ready(function() {
	var _userForm = $('#form_user_add');
	var _editForm = $('#form_user_edit');

	$('#submit_form').click(function() {
		var objUserForm = {
			_robot: $("#robot"),
			_source: $("#source"),
			_url: $("input[name='url']", _userForm),
			_date: $("input[name='date']", _userForm),
			_article: $("#article")
		}

		for (var i in objUserForm) {
			if (objUserForm[i].val() == '' || objUserForm[i].val() == null) {
				objUserForm[i].css({
					'border-color': 'red'
				});
				//layer.tips('必填项',objUserForm[i]);
				return false;
			} else {
				objUserForm[i].css({
					'border-color': '#e5e5e5'
				});
			}
			//alert(objUserForm[i].val());
		}
		$.ajax({
			type: "POST",
			url: "/Logs/addColl",
			dataType: "JSON",
			async: true,
			data: {
				"robot": objUserForm._robot.val(),
				"source": 　objUserForm._source.val(),
				"url": objUserForm._url.val(),
				"date": objUserForm._date.val(),
				"article": objUserForm._article.val()
			},
			success: function(data) {
				window.alert(data.info);
				if (true === data.status) window.location = "/Logs/user";
			},
			error: function(e) {

				console.log(e);
			}


		});
	});

	$('.userDelete').click(function() {
		if (window.confirm("确认删除？")) {
			var userId = $(this).parent('td').attr('item_id');
			$.ajax({
				type: "GET",
				url: $(this).attr('href'),
				async: true,
				data: {
					//"id" : userId
				},
				success: function(data) {
					window.alert(data.info);
					if (true === data.status) window.location = "/Logs/coll";
				}
			});
			return false;
		} else {
			return false;
		}
	});

	$('.userEdit').click(function() {
		$('#modal_edit').modal('toggle');
		var _parent = $(this).parent('td').parent('tr.gradeX');
		userId = $(this).parent('td').attr('item_id');
		robot_id = $(this).parent('td').attr('robot_id');
		source_id = $(this).parent('td').attr('source_id');
		article_id = $(this).parent('td').attr('article_id');
		objEditForm = {
			_robot: $("#robot", _editForm),
			_source: $("#source", _editForm),
			_url: $("input[name='url']", _editForm),
			_article: $("#article", _editForm),
			_date: $("input[name='date']", _editForm)
		};
		var tdTable = [];
		$('td', _parent).each(function() {
			tdTable.push($(this).text());
		});
		objEditForm._url.val(tdTable[2]);
		objEditForm._date.val(tdTable[4]);
		$('option', objEditForm._robot).each(function() {
			if ($(this).val() == robot_id) {
				$(this).attr('selected', true);
			}
		});
		$('option', objEditForm._article).each(function() {
			if ($(this).val() == article_id) {
				$(this).attr('selected', true);
			}
		});
		$('option', objEditForm._source).each(function() {
			if ($(this).val() == source_id) {
				$(this).attr('selected', true);
			}
		});
		return false;
	});
	$('#submitEdit').click(function() {
		for (var i in objEditForm) {
			if (objEditForm[i].val() == '' || objEditForm[i].val() == null) {
				objEditForm[i].css({
					'border-color': 'red'
				});
				return false;
			} else {
				objEditForm[i].css({
					'border-color': '#e5e5e5'
				});
			}
		}
		$.ajax({
			type: "POST",
			url: "/Logs/editColl/id/" + userId,
			async: true,
			data: {
				"article": objEditForm._article.val(),
				"robot": 　objEditForm._robot.val(),
				"source": objEditForm._source.val(),
				"url": objEditForm._url.val(),
				"date": objEditForm._date.val()
			},
			success: function(data) {
				window.alert(data.info);
				if (true === data.status) window.location = "/Logs/coll";
			}
		});
	});

	$(document).on('click', '#page_next,#page_prev,#page_index,#page_end', function() {
		var urlOld = $(this).attr('href'),
			urlArr = urlOld.split("/");
		urlId = urlArr[urlArr.length - 1];
		$.ajax({
			type: 'POST',
			url: '/Logs/collPage/page/' + urlId,
			data: urlId,
			success: function(data) {
				var data = $.parseJSON(data);

				$('#tbody').html('');
				var id = '';

				$.each(data, function(k, v) {

					id = v['authority_id'];

					$('#tbody').append($('<tr class="gradeX"><td>' + v['coll_startTime'] + '</td><td>' + v['typical_name'] + '</td><td>' + v['level_status'] + '</td><td>' + v['location'] + '</td><td>' + v['message'] + '</td><td>' + v['thread'] + '</td><td>' + v['coll_endTime'] + '</td></tr>'));



				});


			}

		});
		$.ajax({
			type: 'POST',
			url: '/Logs/collCurrentPage/page/' + urlId,
			data: urlId,
			success: function(data) {
				console.log(data);
				$('#pages').html(data);
				$('#pages').ready(function() {
					nextBtn = $('#page_next');
				});
			}

		});
		return false;
	});
});
 </script> 

<div id="thispage" data-id="63"></div>
		<!-- BEGIN PAGE -->

		<div class="page-content">

			<!-- BEGIN SAMPLE PORTLET CONFIGURATION MODAL FORM-->

			<div id="portlet-config" class="modal hide">

				<div class="modal-header">

					<button data-dismiss="modal" class="close" type="button"></button>

					<h3>portlet Settings</h3>

				</div>

				<div class="modal-body">

					<p>Here will be a configuration form</p>

				</div>

			</div>

			<!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->

			<!-- BEGIN PAGE CONTAINER-->        

			<div class="container-fluid">

				<!-- BEGIN PAGE HEADER-->

				<div class="row-fluid">

					<div class="span12">

						<!-- BEGIN STYLE CUSTOMIZER -->

						<div class="color-panel hidden-phone">

							<!-- <div class="color-mode-icons icon-color"></div> -->

							<div class="color-mode-icons icon-color-close"></div>

							<div class="color-mode">

								<p>THEME COLOR</p>

								<ul class="inline">

									<li class="color-black current color-default" data-style="default"></li>

									<li class="color-blue" data-style="blue"></li>

									<li class="color-brown" data-style="brown"></li>

									<li class="color-purple" data-style="purple"></li>

									<li class="color-grey" data-style="grey"></li>

									<li class="color-white color-light" data-style="light"></li>

								</ul>

								<label>

									<span>Layout</span>

									<select class="layout-option m-wrap small">

										<option value="fluid" selected>Fluid</option>

										<option value="boxed">Boxed</option>

									</select>

								</label>

								<label>

									<span>Header</span>

									<select class="header-option m-wrap small">

										<option value="fixed" selected>Fixed</option>

										<option value="default">Default</option>

									</select>

								</label>

								<label>

									<span>Sidebar</span>

									<select class="sidebar-option m-wrap small">

										<option value="fixed">Fixed</option>

										<option value="default" selected>Default</option>

									</select>

								</label>

								<label>

									<span>Footer</span>

									<select class="footer-option m-wrap small">

										<option value="fixed">Fixed</option>

										<option value="default" selected>Default</option>

									</select>

								</label>

							</div>

						</div>

						<!-- END BEGIN STYLE CUSTOMIZER -->  

						<!-- BEGIN PAGE TITLE & BREADCRUMB-->

						<h3 class="page-title">
							日志管理

						</h3>

						<ul class="breadcrumb">

							<li>
								<i class="icon-home"></i>
								<span>当前位置：</span>
								<span>首页</span>

								<i class="icon-angle-right"></i>
							</li>

							<li>
								<span>日志管理</span>

								<i class="icon-angle-right"></i>

							</li>

							<li><span>采集日志</span></li>

						</ul>

						<!-- END PAGE TITLE & BREADCRUMB-->

					</div>

				</div>

				<!-- END PAGE HEADER-->

				<!-- BEGIN PAGE CONTENT-->

				<div class="row-fluid">

					<div class="span6 responsive" data-tablet="span12 fix-offset" data-desktop="span6" style="width:100%;">

						<!-- BEGIN EXAMPLE TABLE PORTLET-->

						<div class="portlet box grey">

							<div class="portlet-title">

								<div class="caption"><i class="icon-user"></i>采集日志</div>

								<div class="actions controls">

<!--									<a href="#modal_add" data-toggle="modal" data-target="#modal_add" class="btn blue"><i class="icon-pencil"></i> 添加</a>-->
									<!--<a href="/Index/Authority/add" class="btn blue"><i class="icon-pencil"></i> 添加</a>-->

								</div>

							</div>

							<div class="portlet-body">

								<table class="table table-striped table-bordered table-hover" id="current_table">

									<thead>

										<tr>
											
											<th>开始时间</th>
											<th>文章类型</th>
											<th>日志级别</th>
											<th>代码错误</th>
											<th>日志内容</th>
											<th>线程名称</th>
											<th>结束时间</th>
<!--											<th>操作</th>-->
										</tr>

									</thead>

									<tbody id="tbody">
<?php
    foreach ($colllogs_info as $k => $v) {
    	/*if($v['level'] == "0"){
    		$level_status = "错误";
    	}
    	else if($v['level'] == "1"){
    		$level_status = "正确";
    	}*/
        $style = (0 == ($k % 2)) ? 'odd' : 'even';
        echo <<< EOF
										<tr class="{$style} gradeX">

											<td>{$v['coll_startTime']}</td>
											<td>{$v['typical_name']}</td>
											<td>{$v['level_status']}</td>
											<td>{$v['location']}</td>
											<td>{$v['message']}</td>
											<td>{$v['thread']}</td>
											<td>{$v['coll_endTime']}</td>
									

										</tr>
EOF;
    }
?>
									</tbody>
                </table>
								<div id="pages">
									<?php
									if($list['rows']/$list['every_page']<=1)
									{
									}
									else
									{
										print_r($allpage);
									}
									?>
								</div>

							</div>

						</div>
                        
                        		<div id="modal_add" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" aria-hidden="true">

									<div class="modal-header">

										<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>

										<h3 id="myModalLabel3">添加采集日志</h3>

									</div>

									<div class="modal-body">

										<form action="#" id="form_user_add" method="post" class="form-horizontal">

											<div class="control-group">

												<label class="control-label">采集机器人</label>

												<div class="controls">
													<select id="robot" name="robot">
                                                       <?php
													   foreach($robot_info as $val)
													   {
                                                           echo '<option value="';
														   echo $val['id'] ;
														   echo '">';
														   echo $val['name'];
														   echo "</option>";
													   }
													   ?>
													</select>
												</div>

											</div>

											<div class="control-group">

												<label class="control-label">采集源</label>

												<div class="controls">

													<select id="source" name="source">
														<?php
														foreach($source_info as $val)
														{
															echo '<option value="';
															echo $val['id'] ;
															echo '">';
															echo $val['name'];
															echo "</option>";
														}
														?>
													</select>
												</div>
											</div>
                                            <div class="control-group">
                                                <label class="control-label">采集地址</label>
                                                <div class="controls">
													<input type="text" class="colorpicker-default m-wrap" name="url" value="">
												</div>
        
                                            </div>
                                            
											<div class="control-group">

												<label class="control-label">采集文章</label>
												<div class="controls">
													<select id="article" name="article">
                                                      <?php
														foreach($article_info as $val)
														{
															echo '<option value="';
															echo $val['article_id'] ;
															echo '">';
															echo $val['title'];
															echo "</option>";
														}
													  ?>
													</select>
												</div>
											</div>

											 <div class="control-group">

												<label class="control-label">创建时间</label>

												<div class="controls">

													
													<input placeholder="请输入日期" class="laydate-icon" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"  name="date">

												</div>

											</div>

										</form>

									</div>

									<div class="modal-footer">

										<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>

										<button class="btn green btn-primary" id="submit_form" data-dismiss="modal" >提交</button>

									</div>

								</div>

								<div id="modal_edit" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" aria-hidden="true">

									<div class="modal-header">

										<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>

										<h3 id="myModalLabel3">编辑采集日志</h3>

									</div>

									<div class="modal-body">

										<form action="#" id="form_user_edit" method="post" class="form-horizontal">
											<div class="control-group">
												<label class="control-label">采集机器人</label>

												<div class="controls">

													<select id="robot" name="robot">
														<?php
														foreach($robot_info as $val)
														{
															echo '<option value="';
															echo $val['id'] ;
															echo '">';
															echo $val['name'];
															echo "</option>";
														}
														?>
													</select>
												</div>

											</div>

											<div class="control-group">

												<label class="control-label">采集源</label>

												<div class="controls">

													<select id="source" name="source">
														<?php
														foreach($source_info as $val)
														{
															echo '<option value="';
															echo $val['id'] ;
															echo '">';
															echo $val['name'];
															echo "</option>";
														}
														?>
													</select>

												</div>

											</div>
											                                            
                                            <div class="control-group">

                                                <label class="control-label">采集地址</label>
        										
                                                <div class="controls">

													<input type="text" class="colorpicker-default m-wrap" name="url" value="">
												</div>
                                            </div>
											<div class="control-group">
												<label class="control-label">采集文章</label>
												<div class="controls">
													<select id="article" name="article">
														<?php
														foreach($article_info as $val)
														{
															echo '<option value="';
															echo $val['article_id'] ;
															echo '">';
															echo $val['title'];
															echo "</option>";
														}
														?>
													</select>
												</div>

											</div>

											 <div class="control-group">

												<label class="control-label">创建时间</label>

												<div class="controls">
													<input placeholder="请输入日期" class="laydate-icon" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"  name="date">

												</div>
											</div>
										</form>

									</div>

									<div class="modal-footer">

										<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>

										<button class="btn green btn-primary" id="submitEdit" data-dismiss="modal" >提交</button>
                                        
									</div>

								</div>

						<!-- END EXAMPLE TABLE PORTLET-->

					</div>

				</div>

				<!-- END PAGE CONTENT-->

			</div>

			<!-- END PAGE CONTAINER-->

		</div>

    <!-- END PAGE -->
<?php
    include APPLICATION_PATH . '/application/views/foot.phtml';
?>
